package com.xinchuang.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xinchuang.comment.KeyWord;
import com.xinchuang.comment.R;
import com.xinchuang.domain.entity.*;
import com.xinchuang.domain.vo.*;
import com.xinchuang.entity.api.UserApi;
import com.xinchuang.manager.TestRecordMainTableService;
import com.xinchuang.manager.TestRecordProblemTableService;
import com.xinchuang.manager.TestRecordResumeTableService;
import com.xinchuang.manager.TestRecordSourceTableService;
import com.xinchuang.mapper.*;
import com.xinchuang.role.entity.SystemHeader;
import com.xinchuang.service.OaUserService;
import com.xinchuang.service.RecordAndStatisticModService;
import com.xinchuang.service.actual.CloseQuestionService;
import com.xinchuang.utils.IdUtils;
import com.xinchuang.utils.MyUtils;
import com.xinchuang.utils.PoiUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class RecordAndStatisticModServiceImpl implements RecordAndStatisticModService {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private TestRecordMainTableService testRecordMainTableService;

    @Autowired
    private TestRecordMainTableMapper testRecordMainTableMapper;

    @Autowired
    private TestRecordProblemTableService testRecordProblemTableService;

    @Autowired
    private TestRecordSourceTableService testRecordSourceTableService;

    @Autowired
    private TestRecordResumeTableService testRecordResumeTableService;

    @Autowired
    private CloseQuestionService CloseQuestionService;

    @Autowired
    private KeyWord keyWord;

    @Autowired
    private DictTableMapper dictTableMapper;

    @Autowired
    private TestModelParamMapper testModelParamMapper;

    @Autowired
    private TestModelSubTableMapper testModelSubTableMapper;

    @Autowired
    private TestRecordMainTableMapper recordMainTableMapper;

    @Autowired
    private UserApiMapper userApiMapper;

    @Autowired
    private OaUserService oaUserService;
    @Autowired
    private CloseQuestionService closeQuestionService;

    @Override
    public R tryOutRecordList(JSONObject jsonObject) {
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        TestRecordMainTable recordMainTable = testRecordMainTableService.getOne(
                new LambdaQueryWrapper<TestRecordMainTable>()
                        .eq(TestRecordMainTable::getMoldId, moldId)
                        .orderByDesc(TestRecordMainTable::getCreateTime)
                        .last("LIMIT 1")
        );
        TestModelParam modelParam = testModelParamMapper.selectById(moldId);
        TestModelSubTable subTable = testModelSubTableMapper.selectOne(
                new LambdaQueryWrapper<TestModelSubTable>()
                        .eq(TestModelSubTable::getTryOutTimes, 0)
                        .eq(TestModelSubTable::getMoldId, moldId)
                        .last("LIMIT 1")
        );
        if (ObjectUtil.isNull(recordMainTable)) {
            recordMainTable = new TestRecordMainTable();
        }
        JSONObject resultJson = new JSONObject();
        //
        String projectName = "";
        if (StringUtils.isNotBlank(recordMainTable.getProjectName())) {
            projectName = recordMainTable.getProjectName();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            projectName = modelParam.getProjectName();
        }
        resultJson.put("projectName", MyUtils.getString(projectName));
        //
        resultJson.put("moldId", moldId);
        //
        String moldName = "";
        if (StringUtils.isNotBlank(recordMainTable.getProductName())) {
            moldName = recordMainTable.getProductName();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            moldName = modelParam.getMoldName();
        }
        resultJson.put("moldName", MyUtils.getString(moldName));
        //
        String moldMaterial = "";
        if (StringUtils.isNotBlank(recordMainTable.getProductMaterial())) {
            moldMaterial = recordMainTable.getProductMaterial();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            moldMaterial = modelParam.getMaterials();
        }
        resultJson.put("moldMaterial", MyUtils.getString(moldMaterial));
        //
        String moldWeight = "";
        if (StringUtils.isNotBlank(recordMainTable.getProductWeight())) {
            moldWeight = recordMainTable.getProductWeight();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            moldWeight = modelParam.getSamplePieceWeight();
        }
        resultJson.put("moldWeight", MyUtils.getString(moldWeight));
        //
        JSONArray moldDesigner = new JSONArray();
        if (StringUtils.isNotBlank(recordMainTable.getDesignerUnitId())) {
            moldDesigner.add(Integer.valueOf(recordMainTable.getDesignerUnitId()));
            moldDesigner.add(Integer.valueOf(recordMainTable.getDesignerUserId()));
        } else if (ObjectUtil.isNotNull(modelParam) && StringUtils.isNotBlank(modelParam.getDesignerUnitId())) {
            moldDesigner.add(Integer.valueOf(modelParam.getDesignerUnitId()));
            moldDesigner.add(Integer.valueOf(modelParam.getDesignerUserId()));
        }
        resultJson.put("moldDesigner", moldDesigner);
        //
        String mainEnginePlantId = "";
        if (StringUtils.isNotBlank(recordMainTable.getHostFactory())) {
            mainEnginePlantId = recordMainTable.getHostFactory();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            mainEnginePlantId = modelParam.getCustomerName();
        }
        resultJson.put("mainEnginePlantId", MyUtils.getString(mainEnginePlantId));
        //
        JSONArray projectManager = new JSONArray();
        if (StringUtils.isNotBlank(recordMainTable.getProjectManagerId())) {
            projectManager.add(Integer.valueOf(recordMainTable.getProjectManagerId()));
            projectManager.add(Integer.valueOf(recordMainTable.getProjectManager()));
        } else if (ObjectUtil.isNotNull(modelParam) && StringUtils.isNotEmpty(modelParam.getProjectManagerId())) {
            projectManager.add(Integer.valueOf(modelParam.getProjectManagerId()));
            projectManager.add(Integer.valueOf(modelParam.getProjectManager()));
        }
        resultJson.put("projectManager", projectManager);
        //
        JSONArray tongmanName = new JSONArray();
        if (StringUtils.isNotBlank(recordMainTable.getTongmanId())) {
            tongmanName.add(Integer.valueOf(recordMainTable.getTongmanId()));
            tongmanName.add(Integer.valueOf(recordMainTable.getTongmanName()));
        } else if (ObjectUtil.isNotNull(modelParam) && StringUtils.isNotEmpty(modelParam.getTongmanId())) {
            tongmanName.add(Integer.valueOf(modelParam.getTongmanId()));
            tongmanName.add(Integer.valueOf(modelParam.getTongmanName()));
        }
        resultJson.put("tongmanName", tongmanName);
        //
        String surfaceRequire = "";
        if (StringUtils.isNotBlank(recordMainTable.getSurfaceRequirements())) {
            surfaceRequire = recordMainTable.getSurfaceRequirements();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            surfaceRequire = modelParam.getSurface();
        }
        resultJson.put("surfaceRequire", MyUtils.getString(surfaceRequire));
        //
        String partsStorageBinId = "";
        if (StringUtils.isNotBlank(recordMainTable.getPartFactory())) {
            partsStorageBinId = recordMainTable.getPartFactory();
        } else if (ObjectUtil.isNotNull(modelParam)) {
            partsStorageBinId = modelParam.getPartsFactoryId();
        }
        resultJson.put("partsStorageBinId", MyUtils.getString(partsStorageBinId));
        //
        String tryOutTimeOfT0 = "";
        if (StringUtils.isNotBlank(recordMainTable.getToTime())) {
            tryOutTimeOfT0 = recordMainTable.getToTime();
        } else if (ObjectUtil.isNotNull(subTable) && null != subTable.getPracticalTime()) {
            tryOutTimeOfT0 = DateUtil.format(subTable.getPracticalTime(), "yyyy-MM-dd");
        }
        resultJson.put("tryOutTimeOfT0", tryOutTimeOfT0);
        //
        String draftedBy = "";
        if (StringUtils.isNotBlank(recordMainTable.getPreparer())) {
            UserApi userApi = userApiMapper.selectById(recordMainTable.getPreparer());
            if (ObjectUtil.isNotNull(userApi)) {
                draftedBy = userApi.getName();
            }
        }
        resultJson.put("draftedBy", draftedBy);
        resultJson.put("userId", MyUtils.getString(recordMainTable.getPreparer()));
        resultJson.put("checkoutName", StringUtils.isBlank(recordMainTable.getAuditor()) ? "" : recordMainTable.getAuditor());
        resultJson.put("countersign", StringUtils.isBlank(recordMainTable.getCountersign()) ? "" : recordMainTable.getCountersign());
        resultJson.put("status", StringUtils.isBlank(recordMainTable.getStatus()) ? "" : recordMainTable.getStatus());
        JSONArray stageData = new JSONArray();
        List<TestRecordProblemTable> problemTableList = testRecordProblemTableService.list(
                new LambdaQueryWrapper<TestRecordProblemTable>()
                        .eq(TestRecordProblemTable::getParentRecordId, recordMainTable.getId())
                        .orderByAsc(TestRecordProblemTable::getPhase)
        );
        if (CollectionUtil.isNotEmpty(problemTableList)) {
            JSONObject data;
            for (TestRecordProblemTable problemTable : problemTableList) {
                data = new JSONObject();
                data.put("stageNo", StringUtils.isBlank(problemTable.getPhase()) ? "" : problemTable.getPhase());
                data.put("image", StringUtils.isBlank(problemTable.getImages()) ? "" : problemTable.getImages());
                data.put("questionPoint", StringUtils.isBlank(problemTable.getIssues()) ? "" : problemTable.getIssues());
                data.put("questionTypeName", StringUtils.isBlank(problemTable.getCategories()) ? "" : problemTable.getCategories());
                data.put("totalQuestionCount", StringUtils.isBlank(problemTable.getIssuesTotal()) ? "" : problemTable.getIssuesTotal());
                data.put("needToChangeCount", StringUtils.isBlank(problemTable.getIssuesPending()) ? "" : problemTable.getIssuesPending());
                data.put("reason", StringUtils.isBlank(problemTable.getCauses()) ? "" : problemTable.getCauses());
                data.put("reasonTypeName", StringUtils.isBlank(problemTable.getCauseCategories()) ? "" : problemTable.getCauseCategories());
                data.put("reasonSourceId", "项目组");
                data.put("expertGroup", StringUtils.isBlank(problemTable.getExpertGroup()) ? "" : problemTable.getExpertGroup());
                JSONArray responsiblePersonData = new JSONArray();
                List<TestRecordSourceTable> sourceTables = testRecordSourceTableService.list(
                        new LambdaQueryWrapper<TestRecordSourceTable>()
                                .eq(TestRecordSourceTable::getParentRecordId, problemTable.getProblemId())
                );
                if (CollectionUtil.isNotEmpty(sourceTables)) {
                    JSONObject source;
                    for (TestRecordSourceTable sourceTable : sourceTables) {
                        source = new JSONObject();
                        source.put("departMentName", StringUtils.isBlank(sourceTable.getResponsibleDepartment()) ? "" : sourceTable.getResponsibleDepartment());
                        //责任人
                        JSONArray responsiblePerson;
                        if (StringUtils.isNotBlank(sourceTable.getResponsiblePersonUnitId())) {
                            responsiblePerson = new JSONArray();
                            responsiblePerson.add(Integer.valueOf(sourceTable.getResponsiblePersonUnitId()));
                            responsiblePerson.add(Integer.valueOf(sourceTable.getResponsiblePerson()));
                        } else {
                            responsiblePerson = new JSONArray();
                        }
                        source.put("responsiblePerson", responsiblePerson);
                        source.put("plannedCompletionTime", StringUtils.isBlank(sourceTable.getPlanCompletionTime()) ? "" : sourceTable.getPlanCompletionTime());
                        //责任人自检
                        JSONArray selfCheck;
                        if (StringUtils.isNotBlank(sourceTable.getInspectionUnitId())) {
                            selfCheck = new JSONArray();
                            selfCheck.add(Integer.valueOf(sourceTable.getInspectionUnitId()));
                            selfCheck.add(Integer.valueOf(sourceTable.getInspection()));
                        } else {
                            selfCheck = new JSONArray();
                        }
                        source.put("selfCheck", selfCheck);
                        source.put("remediationAction", StringUtils.isBlank(sourceTable.getRemediationAction()) ? "" : sourceTable.getRemediationAction());
                        if (StringUtils.isNotBlank(sourceTable.getSource())) {
                            data.put("reasonSourceId", sourceTable.getSource());
                        }
                        responsiblePersonData.add(source);
                    }
                }
                JSONArray tryOutResultData = new JSONArray();
                List<TestRecordResumeTable> resumeTables = testRecordResumeTableService.list(
                        new LambdaQueryWrapper<TestRecordResumeTable>()
                                .eq(TestRecordResumeTable::getParentSourceId, problemTable.getProblemId())
                );
                if (CollectionUtil.isNotEmpty(resumeTables)) {
                    JSONObject resume;
                    for (TestRecordResumeTable resumeTable : resumeTables) {
                        resume = new JSONObject();
                        resume.put("stageName", StringUtils.isBlank(resumeTable.getStage()) ? "" : resumeTable.getStage());
                        resume.put("stateValue", StringUtils.isBlank(resumeTable.getStatus()) ? "" : resumeTable.getStatus());
                        resume.put("planValue", StringUtils.isBlank(resumeTable.getPlan()) ? "" : resumeTable.getPlan());
                        resume.put("realValue", StringUtils.isBlank(resumeTable.getActual()) ? "" : resumeTable.getActual());
                        tryOutResultData.add(resume);
                    }
                }
                data.put("responsiblePersonData", responsiblePersonData);
                data.put("tryOutResultData", tryOutResultData);
                stageData.add(data);
            }
        }
        resultJson.put("stageData", stageData);
        return R.data(resultJson);
//        }
//        return R.success("无数据");
    }

    private TryOutRecordListItemVo getTryOutRecordListItemByMoldId(String moldId) {
        TryOutRecordListItemVo tryOutRecordListItem = testRecordMainTableMapper.tryOutRecordList(moldId);
        if (ObjectUtil.isNull(tryOutRecordListItem)) {
            return null;
        }
        String nmid = tryOutRecordListItem.getId();
        List<RecordProblemVo> stageData = testRecordMainTableMapper.getStageData(nmid);
        if (CollectionUtil.isNotEmpty(stageData)) {
            tryOutRecordListItem.getStageData().addAll(stageData);
            for (int i = 0; i < stageData.size(); i++) {
                RecordProblemVo stageDatum = stageData.get(i);
                List<RecordSourceVo> recordSource = testRecordMainTableMapper.getRecordSource(stageDatum.getProblemId());
                if (recordSource.size() > 0) {
                    stageDatum.setReasonSourceId(recordSource.get(0).getSource());
                }
                stageDatum.getResponsiblePersonData().addAll(recordSource);
//                for (RecordSourceVo recordSourceVo : recordSource) {
                List<RecordResumeVo> recordResume = testRecordMainTableMapper.getRecordResume(stageDatum.getProblemId());
                stageDatum.getTryOutResultData().addAll(recordResume);
//                }
            }
        }
        return tryOutRecordListItem;
    }

    @Override
    public String tryOutColsedQuestion(JSONObject jsonObject) {
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");
        if (
                "1".equals(moldId)
        ) {
            return "{\"code\":200,\"data\":{\"moldName\":\"xx\",\"projectManager\":\"xx\",\"moldWeight\":\"32\",\"tongmanName\":\"xx\",\"tryOutTime\":\"202-06-08\",\"moldMaterial\":\"xx\",\"mainEnginePlantId\":\"2\",\"moldId\":\"1\",\"moldDesigner\":\"xxx\",\"partsStorageBin\":\"xx\",\"projectName\":\"xx\",\"stageData\":[{\"realTime\":\"2022-06-08\",\"reason\":\"xx\",\"stageName\":\"T0\",\"totalCloseRate\":\"100%\",\"raisedCount\":\"1\",\"stageCloseRate\":\"100%\",\"plannedTime\":\"2022-06-08\",\"plannedDoneCount\":\"2\",\"totalCount\":\"3\",\"needToChangeCount\":\"0\",\"closedCount\":\"2\"}],\"surfaceRequire\":\"xx\"},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    @Transactional
    public synchronized String addTryOutRecord(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取钳工责任人
        JSONArray tongmanName = jsonObject.getJSONArray("tongmanName");
        //jsonobject解析获取设计责任人
        JSONArray moldDesigner = jsonObject.getJSONArray("moldDesigner");
        //jsonobject解析获取项目责任人
        JSONArray projectManager = jsonObject.getJSONArray("projectManager");
        //jsonobject解析获取产品表面要求
        String surfaceRequire = jsonObject.getString("surfaceRequire");
        //jsonobject解析获取T0试模时间
        String tryOutTimeOfT0 = jsonObject.getString("tryOutTimeOfT0");
        //jsonobject解析获取审核状态
        String status = jsonObject.getString("status");
        //jsonobject解析获取产品重量
        String moldWeight = jsonObject.getString("moldWeight");
        //jsonobject解析获取产品材质
        String moldMaterial = jsonObject.getString("moldMaterial");
        //jsonobject解析获取产品名称
        String moldName = jsonObject.getString("moldName");
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取零件厂Id
        String partsStorageBinId = jsonObject.getString("partsStorageBinId");
        //jsonobject解析获取主机厂Id
        String mainEnginePlantId = jsonObject.getString("mainEnginePlantId");
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取阶段数据
        JSONArray array = jsonObject.getJSONArray("stageData");
        //jsonobject解析获取拟定人
//        String draftedBy = jsonObject.getString("draftedBy");
        SystemHeader header = MyUtils.getHeader(request);
        UserApi userApi = userApiMapper.selectById(header.getId());
        String userId = "";
        //删除历史数据
        {
            TestRecordMainTable recordMainTable = testRecordMainTableService.getOne(
                    new LambdaQueryWrapper<TestRecordMainTable>()
                            .eq(TestRecordMainTable::getMoldId, moldId)
                            .orderByDesc(TestRecordMainTable::getCreateTime)
                            .last("LIMIT 1")
            );
            if (ObjectUtil.isNotNull(recordMainTable)) {
                if (StringUtils.isNotBlank(recordMainTable.getPreparer())
                        && !recordMainTable.getPreparer().equals(userApi.getUserId() + "")) {
                    UserApi api = userApiMapper.selectById(recordMainTable.getPreparer());
                    if (ObjectUtil.isNotNull(api)) {
                        return JSON.toJSONString(R.fail("该审评表属于(" + api.getName() + ")不属于您,暂无权限修改"));
                    }
                } else {
                    userId = header.getId();
                }
                List<TestRecordProblemTable> problemTableList = testRecordProblemTableService.list(
                        new LambdaQueryWrapper<TestRecordProblemTable>()
                                .eq(TestRecordProblemTable::getParentRecordId, recordMainTable.getId()));
                if (CollectionUtil.isNotEmpty(problemTableList)) {
                    for (TestRecordProblemTable problemTable : problemTableList) {
                        testRecordProblemTableService.removeById(problemTable.getProblemId());
                        List<TestRecordSourceTable> sourceTables = testRecordSourceTableService.list(new LambdaQueryWrapper<TestRecordSourceTable>().eq(TestRecordSourceTable::getParentRecordId, problemTable.getProblemId()));
                        if (CollectionUtil.isNotEmpty(sourceTables)) {
                            for (TestRecordSourceTable sourceTable : sourceTables) {
                                testRecordSourceTableService.removeById(sourceTable.getSourceId());
                            }
                        }
                        List<TestRecordResumeTable> resumeTables = testRecordResumeTableService.list(new LambdaQueryWrapper<TestRecordResumeTable>().eq(TestRecordResumeTable::getParentSourceId, problemTable.getProblemId()));
                        if (CollectionUtil.isNotEmpty(resumeTables)) {
                            for (TestRecordResumeTable resumeTable : resumeTables) {
                                testRecordResumeTableService.removeById(resumeTable.getResumeId());
                            }
                        }
                    }
                }
                testRecordMainTableService.removeById(recordMainTable.getId());
            } else {
                userId = header.getId();
            }
        }

        String recordMainTableId = IdUtils.simpleUUID();
        TestRecordMainTable testRecordMainTable = new TestRecordMainTable(
                recordMainTableId, moldId, projectName, moldName,
                moldMaterial, moldWeight, mainEnginePlantId, null,
                null, null, surfaceRequire, partsStorageBinId,
                tryOutTimeOfT0, userId, null, null,
                status, new Date(), new Date(), null, null);
        if (CollectionUtil.isNotEmpty(tongmanName)) {
            testRecordMainTable.setTongmanId(tongmanName.getString(0));
            testRecordMainTable.setTongmanName(tongmanName.getString(1));
        }
        if (CollectionUtil.isNotEmpty(moldDesigner)) {
            testRecordMainTable.setDesignerUnitId(moldDesigner.getString(0));
            testRecordMainTable.setDesignerUserId(moldDesigner.getString(1));
        }
        if (CollectionUtil.isNotEmpty(projectManager)) {
            testRecordMainTable.setProjectManagerId(projectManager.getString(0));
            testRecordMainTable.setProjectManager(projectManager.getString(1));
        }
        testRecordMainTableService.save(testRecordMainTable);

        List<RecordProblemToVo> stageData = JSONArray.parseArray(array.toJSONString(), RecordProblemToVo.class);
        for (RecordProblemToVo stageDatum : stageData) {
            TestRecordProblemTable testRecordProblemTable = new TestRecordProblemTable();
            BeanUtils.copyProperties(stageDatum, testRecordProblemTable);
            String problemId = IdUtils.simpleUUID();
            testRecordProblemTable.setProblemId(problemId);
            testRecordProblemTable.setParentRecordId(recordMainTableId);
            testRecordProblemTable.setPhase(stageDatum.getStageNo());
            testRecordProblemTable.setImages(stageDatum.getImage());
            testRecordProblemTable.setIssues(stageDatum.getQuestionPoint());
            testRecordProblemTable.setCategories(stageDatum.getQuestionTypeName());
            testRecordProblemTable.setIssuesTotal(stageDatum.getTotalQuestionCount());
            testRecordProblemTable.setIssuesPending(stageDatum.getNeedToChangeCount());
            testRecordProblemTable.setCauses(stageDatum.getReason());
            testRecordProblemTable.setCauseCategories(stageDatum.getReasonTypeName());
            testRecordProblemTable.setExpertGroup(stageDatum.getExpertGroup());
            testRecordProblemTable.setCreateTime(new Date());
            testRecordProblemTable.setUpdateTime(new Date());
            testRecordProblemTableService.save(testRecordProblemTable);
            List<RecordSourceToVo> responsiblePersonData = stageDatum.getResponsiblePersonData();
            for (int i = 0; i < responsiblePersonData.size(); i++) {
                RecordSourceToVo recordSourceVo = responsiblePersonData.get(i);
                TestRecordSourceTable testRecordSourceTable = new TestRecordSourceTable();
                testRecordSourceTable.setSourceId(recordSourceVo.getSourceId());
                testRecordSourceTable.setParentRecordId(problemId);
                testRecordSourceTable.setSource(stageDatum.getReasonSourceId());
                testRecordSourceTable.setResponsibleDepartment(recordSourceVo.getDepartMentName());
                JSONArray responsiblePerson = recordSourceVo.getResponsiblePerson();
                if (CollectionUtil.isNotEmpty(responsiblePerson)) {
                    testRecordSourceTable.setResponsiblePersonUnitId(responsiblePerson.getString(0));
                    testRecordSourceTable.setResponsiblePerson(responsiblePerson.getString(1));
                }
                testRecordSourceTable.setPlanCompletionTime(recordSourceVo.getPlannedCompletionTime());
                JSONArray selfCheck = recordSourceVo.getSelfCheck();
                if (CollectionUtil.isNotEmpty(selfCheck)) {
                    testRecordSourceTable.setInspectionUnitId(selfCheck.getString(0));
                    testRecordSourceTable.setInspection(selfCheck.getString(1));
                }
                testRecordSourceTable.setRemediationAction(recordSourceVo.getRemediationAction());
                testRecordSourceTable.setCreateTime(new Date());
                testRecordSourceTable.setUpdateTime(new Date());
                testRecordSourceTableService.save(testRecordSourceTable);
            }
            List<RecordResumeVo> tryOutResultData = stageDatum.getTryOutResultData();
            for (int i = 0; i < tryOutResultData.size(); i++) {
                TestRecordResumeTable testRecordResumeTable = new TestRecordResumeTable();
                RecordResumeVo recordResumeVo = tryOutResultData.get(i);
                BeanUtils.copyProperties(recordResumeVo, testRecordResumeTable);
                testRecordResumeTable.setParentSourceId(problemId);
                testRecordResumeTable.setStage(recordResumeVo.getStageName());
                testRecordResumeTable.setStatus(recordResumeVo.getStateValue());
                testRecordResumeTable.setPlan(recordResumeVo.getPlanValue());
                testRecordResumeTable.setActual(recordResumeVo.getRealValue());
                testRecordResumeTable.setCreateTime(new Date());
                testRecordResumeTable.setUpdateTime(new Date());
                testRecordResumeTableService.save(testRecordResumeTable);
            }
        }
        return JSON.toJSONString(R.success("保存成功"));
    }

    @Override
    public String postTryOutToCheck(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");

        //查询该审批表归属与判断
        SystemHeader header = MyUtils.getHeader(request);
        UserApi userApi = userApiMapper.selectById(header.getId());
        TestRecordMainTable recordMainTable = testRecordMainTableService.getOne(
                new LambdaQueryWrapper<TestRecordMainTable>()
                        .eq(TestRecordMainTable::getMoldId, moldId)
                        .orderByDesc(TestRecordMainTable::getCreateTime)
                        .last("LIMIT 1"));
        if (ObjectUtil.isNotNull(recordMainTable)) {
            if (StringUtils.isNotBlank(recordMainTable.getPreparer())
                    && !recordMainTable.getPreparer().equals(userApi.getUserId() + "")) {
                UserApi api = userApiMapper.selectById(recordMainTable.getPreparer());
                if (ObjectUtil.isNotNull(api)) {
                    return JSON.toJSONString(R.fail("该审评表属于(" + api.getName() + ")不属于您,暂无权限提交"));
                }
            }
        }

        LambdaUpdateWrapper<TestRecordMainTable> testRecordMainTableLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        testRecordMainTableLambdaUpdateWrapper
                .eq(TestRecordMainTable::getMoldId, moldId)
                .set(TestRecordMainTable::getStatus, "2");
        // TODO 请求甲方接口
        boolean update = testRecordMainTableService.update(testRecordMainTableLambdaUpdateWrapper);
        if (update) {
            HashMap<String, Object> result = new HashMap<>();
            result.put("moldId", moldId);
            result.put("status", 2);
        }
        return JSON.toJSONString(R.success("已提交"));
    }

    @Override
    public String exportTryOutRecord(JSONObject jsonObject, HttpServletResponse response) throws IOException {
        //jsonobject解析获取模具Id
        String moldId = jsonObject.getString("moldId");
        TryOutRecordListItemVo tryOutRecordListItem = getTryOutRecordListItemByMoldId(moldId);
        TestRecordMainTable recordMainTable = recordMainTableMapper.selectOne(
                new QueryWrapper<TestRecordMainTable>()
                        .lambda()
                        .eq(TestRecordMainTable::getMoldId, moldId)
                        .orderByDesc(TestRecordMainTable::getCreateTime)
                        .last("LIMIT 1")
        );
        JSONArray tryOutColsedQuestionStageData = new JSONArray();
        if (ObjectUtil.isNotNull(recordMainTable)) {
            tryOutColsedQuestionStageData = CloseQuestionService.tryOutColsedQuestionStageData(recordMainTable);
        }
        if (ObjectUtil.isNull(tryOutRecordListItem)) {
            return JSON.toJSONString(R.fail("模型数据不存在/已删除"));
        }
        // 居中
        ArrayList<CellRangeAddress> rangeCells = new ArrayList<>();
        // 左对齐
        ArrayList<HSSFCell> leftCenterCells = new ArrayList<>();
        // 右对齐加粗
        ArrayList<HSSFCell> rightCenterCells = new ArrayList<>();
        // 居中
        ArrayList<HSSFCell> centerCenterCells = new ArrayList<>();
        // 居中 黄
        ArrayList<HSSFCell> centerCenterYellowBackCells = new ArrayList<>();
        // 居中 屎黄
        ArrayList<HSSFCell> centerCenterBlankYellowBackCells = new ArrayList<>();
        // 居中 红
        ArrayList<HSSFCell> centerCenterRedBackCells = new ArrayList<>();
        // 居中 绿
        ArrayList<HSSFCell> centerCenterGreenBackCells = new ArrayList<>();
        // 居中无边框
        ArrayList<HSSFCell> centerCenterNoBorderCells = new ArrayList<>();


        //创建Excel文件，并把activityList写入到excel中
        HSSFWorkbook workbook = new HSSFWorkbook();

        // 加粗字体
        Font boldFont = workbook.createFont();
        boldFont.setBold(true);


        //创建第一页
        HSSFSheet sheet = workbook.createSheet("试模评审记录表");
        sheet.setDefaultColumnWidth(10);
        // 开始合并单元格
        /*CellRangeAddress cellAddresses6 = CellRangeAddress.valueOf("A1:AL2");
        sheet.addMergedRegion(cellAddresses6);
        rangeCells.add(cellAddresses6);*/
        // 添加logo
        try {
            InputStream inputStream = getClass().getClassLoader().getResourceAsStream("templates/excelLogo.png");
            ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
            BufferedImage bufferImg = ImageIO.read(inputStream);

            // 将图片写入流中
            ImageIO.write(bufferImg, "png", byteArrayOut);
            // 利用HSSFPatriarch将图片写入EXCEL
            Drawing patriarch = sheet.createDrawingPatriarch();
            /**
             * 该构造函数有8个参数
             * 前四个参数是控制图片在单元格的位置，分别是图片距离单元格left，top，right，bottom的像素距离
             * 后四个参数，前连个表示图片左上角所在的cellNum和 rowNum，后天个参数对应的表示图片右下角所在的cellNum和 rowNum，
             * excel中的cellNum和rowNum的index都是从0开始的
             *
             */
            //图片一导出到单元格
            HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
                    (short) 0, 0, (short) 5, 2);
            // 插入图片
            patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));

        } catch (IOException e) {
            throw new RuntimeException("导出图片无效，请联系管理员吧");
        }

        HSSFRow row1 = sheet.createRow(1);
        row1.createCell(13).setCellValue("质量记录");

        CellRangeAddress cellAddresses0_R = CellRangeAddress.valueOf("R1:S2");
        sheet.addMergedRegion(cellAddresses0_R);

        HSSFRow row0 = sheet.createRow(0);
        HSSFCell cell0_R1 = row0.createCell(17);
        cell0_R1.setCellValue("内网路径：");
        centerCenterNoBorderCells.add(cell0_R1);
        CellRangeAddress cellAddresses0_T = CellRangeAddress.valueOf("T1:AV2");
        sheet.addMergedRegion(cellAddresses0_T);

        CellRangeAddress cellAddresses3_1 = CellRangeAddress.valueOf("A3:E3");
        sheet.addMergedRegion(cellAddresses3_1);
        rangeCells.add(cellAddresses3_1);
        CellRangeAddress cellAddresses3_2 = CellRangeAddress.valueOf("F3:S3");
        sheet.addMergedRegion(cellAddresses3_2);
        rangeCells.add(cellAddresses3_2);
        CellRangeAddress cellAddresses3_3 = CellRangeAddress.valueOf("T3:AA3");
        sheet.addMergedRegion(cellAddresses3_3);
        rangeCells.add(cellAddresses3_3);

        CellRangeAddress cellAddresses7 = CellRangeAddress.valueOf("A4:B4");
        sheet.addMergedRegion(cellAddresses7);
        rangeCells.add(cellAddresses7);
        CellRangeAddress cellAddresses8 = CellRangeAddress.valueOf("A5:B5");
        sheet.addMergedRegion(cellAddresses8);
        CellRangeAddress cellAddresses9 = CellRangeAddress.valueOf("C4:E4");
        sheet.addMergedRegion(cellAddresses9);
        rangeCells.add(cellAddresses9);
        CellRangeAddress cellAddresses10 = CellRangeAddress.valueOf("C5:E5");
        sheet.addMergedRegion(cellAddresses10);
        rangeCells.add(cellAddresses10);
        CellRangeAddress cellAddresses11 = CellRangeAddress.valueOf("F4:G4");
        sheet.addMergedRegion(cellAddresses11);
        rangeCells.add(cellAddresses11);
        CellRangeAddress cellAddresses12 = CellRangeAddress.valueOf("F5:G5");
        sheet.addMergedRegion(cellAddresses12);
        rangeCells.add(cellAddresses12);
        CellRangeAddress cellAddresses13 = CellRangeAddress.valueOf("H4:J4");
        sheet.addMergedRegion(cellAddresses13);
        rangeCells.add(cellAddresses13);
        CellRangeAddress cellAddresses14 = CellRangeAddress.valueOf("H5:J5");
        sheet.addMergedRegion(cellAddresses14);
        rangeCells.add(cellAddresses14);
        CellRangeAddress cellAddresses15 = CellRangeAddress.valueOf("K4:L4");
        sheet.addMergedRegion(cellAddresses15);
        rangeCells.add(cellAddresses15);
        CellRangeAddress cellAddresses16 = CellRangeAddress.valueOf("K5:L5");
        sheet.addMergedRegion(cellAddresses16);
        rangeCells.add(cellAddresses16);
        CellRangeAddress cellAddresses17 = CellRangeAddress.valueOf("M4:O4");
        sheet.addMergedRegion(cellAddresses17);
        rangeCells.add(cellAddresses17);
        CellRangeAddress cellAddresses18 = CellRangeAddress.valueOf("M5:O5");
        sheet.addMergedRegion(cellAddresses18);
        rangeCells.add(cellAddresses18);
        CellRangeAddress cellAddresses19 = CellRangeAddress.valueOf("P4:Q4");
        sheet.addMergedRegion(cellAddresses19);
        rangeCells.add(cellAddresses19);
        CellRangeAddress cellAddresses20 = CellRangeAddress.valueOf("P5:Q5");
        sheet.addMergedRegion(cellAddresses20);
        rangeCells.add(cellAddresses20);
        CellRangeAddress cellAddresses21 = CellRangeAddress.valueOf("R4:S4");
        sheet.addMergedRegion(cellAddresses21);
        rangeCells.add(cellAddresses21);
        CellRangeAddress cellAddresses22 = CellRangeAddress.valueOf("R5:S5");
        sheet.addMergedRegion(cellAddresses22);
        rangeCells.add(cellAddresses22);
        // 产品重量
        CellRangeAddress cellAddresses23 = CellRangeAddress.valueOf("T4:U4");
        sheet.addMergedRegion(cellAddresses23);
        rangeCells.add(cellAddresses23);
        CellRangeAddress cellAddresses24 = CellRangeAddress.valueOf("T5:U5");
        sheet.addMergedRegion(cellAddresses24);
        rangeCells.add(cellAddresses24);
        CellRangeAddress cellAddresses25 = CellRangeAddress.valueOf("V4:W4");
        sheet.addMergedRegion(cellAddresses25);
        rangeCells.add(cellAddresses25);
        CellRangeAddress cellAddresses26 = CellRangeAddress.valueOf("V5:W5");
        sheet.addMergedRegion(cellAddresses26);
        rangeCells.add(cellAddresses26);
        CellRangeAddress cellAddresses27 = CellRangeAddress.valueOf("X4:Y4");
        sheet.addMergedRegion(cellAddresses27);
        rangeCells.add(cellAddresses27);
        CellRangeAddress cellAddresses28 = CellRangeAddress.valueOf("X5:Y5");
        sheet.addMergedRegion(cellAddresses28);
        rangeCells.add(cellAddresses28);
        CellRangeAddress cellAddresses29 = CellRangeAddress.valueOf("Z4:AA4");
        sheet.addMergedRegion(cellAddresses29);
        rangeCells.add(cellAddresses29);
        CellRangeAddress cellAddresses30 = CellRangeAddress.valueOf("Z5:AA5");
        sheet.addMergedRegion(cellAddresses30);
        rangeCells.add(cellAddresses30);
        // 空行
        CellRangeAddress cellAddressesBlankLine = CellRangeAddress.valueOf("A6:AA6");
        sheet.addMergedRegion(cellAddressesBlankLine);
        rangeCells.add(cellAddressesBlankLine);

        // 试模结果
        // 试模阶段
        CellRangeAddress cellAddresses7_00 = CellRangeAddress.valueOf("A7:D7");
        sheet.addMergedRegion(cellAddresses7_00);
        rangeCells.add(cellAddresses7_00);
        // 试模原因
        CellRangeAddress cellAddresses8_00 = CellRangeAddress.valueOf("A8:B8");
        sheet.addMergedRegion(cellAddresses8_00);
        rangeCells.add(cellAddresses8_00);
        CellRangeAddress cellAddresses8_01 = CellRangeAddress.valueOf("C8:D8");
        sheet.addMergedRegion(cellAddresses8_01);
        rangeCells.add(cellAddresses8_01);
        // 试模时间
        CellRangeAddress cellAddresses9_00 = CellRangeAddress.valueOf("A9:B10");
        sheet.addMergedRegion(cellAddresses9_00);
        rangeCells.add(cellAddresses9_00);
        CellRangeAddress cellAddresses9_01 = CellRangeAddress.valueOf("C9:D9");
        sheet.addMergedRegion(cellAddresses9_01);
        rangeCells.add(cellAddresses9_01);
        CellRangeAddress cellAddresses10_01 = CellRangeAddress.valueOf("C10:D10");
        sheet.addMergedRegion(cellAddresses10_01);
        rangeCells.add(cellAddresses10_01);
        // 提出问题数
        CellRangeAddress cellAddresses11_00 = CellRangeAddress.valueOf("A11:B12");
        sheet.addMergedRegion(cellAddresses11_00);
        rangeCells.add(cellAddresses11_00);
        CellRangeAddress cellAddresses11_01 = CellRangeAddress.valueOf("C11:D11");
        sheet.addMergedRegion(cellAddresses11_01);
        rangeCells.add(cellAddresses11_01);
        CellRangeAddress cellAddresses12_01 = CellRangeAddress.valueOf("C12:D12");
        sheet.addMergedRegion(cellAddresses12_01);
        rangeCells.add(cellAddresses12_01);
        // 关闭问题数
        CellRangeAddress cellAddresses13_00 = CellRangeAddress.valueOf("A13:B15");
        sheet.addMergedRegion(cellAddresses13_00);
        rangeCells.add(cellAddresses13_00);
        CellRangeAddress cellAddresses13_01 = CellRangeAddress.valueOf("C13:D13");
        sheet.addMergedRegion(cellAddresses13_01);
        rangeCells.add(cellAddresses13_01);
        CellRangeAddress cellAddresses14_01 = CellRangeAddress.valueOf("C14:D14");
        sheet.addMergedRegion(cellAddresses14_01);
        rangeCells.add(cellAddresses14_01);
        CellRangeAddress cellAddresses15_01 = CellRangeAddress.valueOf("C15:D15");
        sheet.addMergedRegion(cellAddresses15_01);
        rangeCells.add(cellAddresses15_01);
        // 问题关闭率
        CellRangeAddress cellAddresses16_00 = CellRangeAddress.valueOf("A16:B17");
        sheet.addMergedRegion(cellAddresses16_00);
        rangeCells.add(cellAddresses16_00);
        CellRangeAddress cellAddresses16_01 = CellRangeAddress.valueOf("C16:D16");
        sheet.addMergedRegion(cellAddresses16_01);
        rangeCells.add(cellAddresses16_01);
        CellRangeAddress cellAddresses17_01 = CellRangeAddress.valueOf("C17:D17");
        sheet.addMergedRegion(cellAddresses17_01);
        rangeCells.add(cellAddresses17_01);

        // 产品图片
        CellRangeAddress cellAddressesProductPic = CellRangeAddress.valueOf("AB3:AV9");
        sheet.addMergedRegion(cellAddressesProductPic);
        rangeCells.add(cellAddressesProductPic);
        // 备注
        CellRangeAddress cellAddressesRemark = CellRangeAddress.valueOf("AB10:AV17");
        sheet.addMergedRegion(cellAddressesRemark);
        rangeCells.add(cellAddressesRemark);


        // 序号
        CellRangeAddress cellAddresses31 = CellRangeAddress.valueOf("A18:A19");
        sheet.addMergedRegion(cellAddresses31);
        rangeCells.add(cellAddresses31);
        CellRangeAddress cellAddresses32 = CellRangeAddress.valueOf("B18:B19");
        sheet.addMergedRegion(cellAddresses32);
        rangeCells.add(cellAddresses32);
        // 略图
        CellRangeAddress cellAddresses33 = CellRangeAddress.valueOf("C18:E19");
        sheet.addMergedRegion(cellAddresses33);
        rangeCells.add(cellAddresses33);
        CellRangeAddress cellAddresses34 = CellRangeAddress.valueOf("F18:J18");
        sheet.addMergedRegion(cellAddresses34);
        rangeCells.add(cellAddresses34);

        // 问题点
        CellRangeAddress cellAddressesProblem = CellRangeAddress.valueOf("F19:G19");
        sheet.addMergedRegion(cellAddressesProblem);
        rangeCells.add(cellAddressesProblem);

        CellRangeAddress cellAddresses35 = CellRangeAddress.valueOf("K18:O18");
        sheet.addMergedRegion(cellAddresses35);
        rangeCells.add(cellAddresses35);

        // 原因
        CellRangeAddress cellAddressesReason = CellRangeAddress.valueOf("K19:N19");
        sheet.addMergedRegion(cellAddressesReason);
        rangeCells.add(cellAddressesReason);

        // 问题来源
        CellRangeAddress cellAddresses36 = CellRangeAddress.valueOf("P18:P19");
        sheet.addMergedRegion(cellAddresses36);
        rangeCells.add(cellAddresses36);
        CellRangeAddress cellAddresses37 = CellRangeAddress.valueOf("Q18:Q19");
        sheet.addMergedRegion(cellAddresses37);
        rangeCells.add(cellAddresses37);
        CellRangeAddress cellAddresses38 = CellRangeAddress.valueOf("R18:R19");
        sheet.addMergedRegion(cellAddresses38);
        rangeCells.add(cellAddresses38);
        CellRangeAddress cellAddresses39 = CellRangeAddress.valueOf("S18:U19");
        sheet.addMergedRegion(cellAddresses39);
        rangeCells.add(cellAddresses39);
        CellRangeAddress cellAddresses40 = CellRangeAddress.valueOf("V18:W19");
        sheet.addMergedRegion(cellAddresses40);
        rangeCells.add(cellAddresses40);
        CellRangeAddress cellAddresses41 = CellRangeAddress.valueOf("X18:Y19");
        sheet.addMergedRegion(cellAddresses41);
        rangeCells.add(cellAddresses41);
        CellRangeAddress cellAddresses42 = CellRangeAddress.valueOf("Z18:Z19");
        sheet.addMergedRegion(cellAddresses42);
        rangeCells.add(cellAddresses42);
        CellRangeAddress cellAddresses43 = CellRangeAddress.valueOf("AA18:AA19");
        sheet.addMergedRegion(cellAddresses43);
        rangeCells.add(cellAddresses43);
        CellRangeAddress cellAddresses44 = CellRangeAddress.valueOf("AB18:AV18");
        sheet.addMergedRegion(cellAddresses44);
        rangeCells.add(cellAddresses44);

        HSSFRow row2 = sheet.createRow(2);
        HSSFCell cell20 = row2.createCell(0);
        cell20.setCellValue("名称：试模后评审记录表");
        HSSFCell cell25 = row2.createCell(5);
        cell25.setCellValue("编号：QR/HT-MJ-194");
        HSSFCell cell219 = row2.createCell(19);
        cell219.setCellValue("版本：D/6");
        // 产品图片
        HSSFCell cellProductPic = row2.createCell(27);
        // 添加产品图片
        TestModelParam testModelParam = testModelParamMapper.selectById(moldId);
        String productImageUrl = testModelParam.getProductImage();
        if (StringUtils.isNotEmpty(productImageUrl)) {
            try {
                ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
                BufferedImage bufferImg = ImageIO.read(new File(keyWord.getFileUrl() + "/" + productImageUrl));
                // 将图片写入流中
                ImageIO.write(bufferImg, "png", byteArrayOut);
                // 利用HSSFPatriarch将图片写入EXCEL
                Drawing patriarch = sheet.createDrawingPatriarch();
                /**
                 * 该构造函数有8个参数
                 * 前四个参数是控制图片在单元格的位置，分别是图片距离单元格left，top，right，bottom的像素距离
                 * 后四个参数，前连个表示图片左上角所在的cellNum和 rowNum，后天个参数对应的表示图片右下角所在的cellNum和 rowNum，
                 * excel中的cellNum和rowNum的index都是从0开始的
                 *
                 */
                //图片一导出到单元格
                HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
                        (short) 35, 2, (short) 38, 9);
                // 插入图片
                patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));

            } catch (IOException e) {
                throw new RuntimeException("导出图片无效，请联系管理员吧");
            }
        }
        HSSFRow row3 = sheet.createRow(3);
        HSSFCell cell30 = row3.createCell(0);
        cell30.setCellValue("项目名称:");
        rightCenterCells.add(cell30);
        HSSFCell cell3_2 = row3.createCell(2);
        cell3_2.setCellValue(tryOutRecordListItem.getProjectName());
        leftCenterCells.add(cell3_2);
        HSSFCell cell3_5 = row3.createCell(5);
        cell3_5.setCellValue("产品名称:");
        rightCenterCells.add(cell3_5);
        HSSFCell cell3_7 = row3.createCell(7);
        cell3_7.setCellValue(tryOutRecordListItem.getMoldName());
        leftCenterCells.add(cell3_7);
        HSSFCell cell3_10 = row3.createCell(10);
        cell3_10.setCellValue("模具工号:");
        rightCenterCells.add(cell3_10);
        HSSFCell cell3_12 = row3.createCell(12);
        cell3_12.setCellValue(tryOutRecordListItem.getMoldId());
        leftCenterCells.add(cell3_12);
        HSSFCell cell3_15 = row3.createCell(15);
        cell3_15.setCellValue("产品材质:");
        rightCenterCells.add(cell3_15);
        HSSFCell cell3_17 = row3.createCell(17);
        cell3_17.setCellValue(tryOutRecordListItem.getMoldMaterial());
        leftCenterCells.add(cell3_17);
        HSSFCell cell3_22 = row3.createCell(19);
        cell3_22.setCellValue("产品重量:");
        rightCenterCells.add(cell3_22);
        HSSFCell cell3_25 = row3.createCell(21);
        cell3_25.setCellValue(tryOutRecordListItem.getMoldWeight());
        leftCenterCells.add(cell3_25);
        HSSFCell cell3_30 = row3.createCell(23);
        cell3_30.setCellValue("主机厂:");
        rightCenterCells.add(cell3_30);
        HSSFCell cell3_33 = row3.createCell(25);
        cell3_33.setCellValue(tryOutRecordListItem.getMainEnginePlantId());
        leftCenterCells.add(cell3_33);

        HSSFRow row4 = sheet.createRow(4);
        HSSFCell cell40 = row4.createCell(0);
        cell40.setCellValue("项目负责人:");
        rightCenterCells.add(cell40);
        HSSFCell cell4_2 = row4.createCell(2);
        cell4_2.setCellValue(oaUserService.getOaUserName(tryOutRecordListItem.getProjectManager()));
        leftCenterCells.add(cell4_2);
        HSSFCell cell4_5 = row4.createCell(5);
        cell4_5.setCellValue("设计责任人:");
        rightCenterCells.add(cell4_5);
        HSSFCell cell4_7 = row4.createCell(7);
        cell4_7.setCellValue(oaUserService.getOaUserName(tryOutRecordListItem.getMoldDesigner()));
        leftCenterCells.add(cell4_7);
        HSSFCell cell4_10 = row4.createCell(10);
        cell4_10.setCellValue("钳工责任人:");
        rightCenterCells.add(cell4_10);
        HSSFCell cell4_12 = row4.createCell(12);
        cell4_12.setCellValue(oaUserService.getOaUserName(tryOutRecordListItem.getTongmanName()));
        leftCenterCells.add(cell4_12);
        HSSFCell cell4_15 = row4.createCell(15);
        cell4_15.setCellValue("产品表面要求:");
        rightCenterCells.add(cell4_15);
        HSSFCell cell4_17 = row4.createCell(17);
        cell4_17.setCellValue(tryOutRecordListItem.getSurfaceRequire());
        leftCenterCells.add(cell4_17);
        HSSFCell cell4_22 = row4.createCell(19);
        cell4_22.setCellValue("零件厂:");
        rightCenterCells.add(cell4_22);
        HSSFCell cell4_25 = row4.createCell(21);
        String partsStorageBin = "";
        DictTable dictTable = dictTableMapper.selectById(tryOutRecordListItem.getPartsStorageBinId());
        if (ObjectUtil.isNotNull(dictTable)) {
            partsStorageBin = dictTable.getDicName();
        }
        cell4_25.setCellValue(partsStorageBin);
        leftCenterCells.add(cell4_25);
        HSSFCell cell4_30 = row4.createCell(23);
        cell4_30.setCellValue("T0:");
        rightCenterCells.add(cell4_30);
        HSSFCell cell4_33 = row4.createCell(25);
        cell4_33.setCellValue(tryOutRecordListItem.getTryOutTimeOfT0());
        leftCenterCells.add(cell4_33);

        // 试模阶段
        HSSFRow rowStage = sheet.createRow(6);
        HSSFCell cellStage_0 = rowStage.createCell(0);
        cellStage_0.setCellValue("试模阶段");
        centerCenterNoBorderCells.add(cellStage_0);
        for (int i = 0; i < 23; i++) {
            HSSFCell cellStage_T = rowStage.createCell(4 + i);
            cellStage_T.setCellValue("T" + i);
            centerCenterCells.add(cellStage_T);
        }
        // 试模原因
        HSSFRow rowReason = sheet.createRow(7);
        HSSFCell cellReason0_0 = rowReason.createCell(0);
        cellReason0_0.setCellValue("试模原因");
        centerCenterNoBorderCells.add(cellReason0_0);
        // 试模时间
        HSSFRow rowTime = sheet.createRow(8);
        HSSFCell cellTime0_0 = rowTime.createCell(0);
        cellTime0_0.setCellValue("试模时间");
        centerCenterNoBorderCells.add(cellTime0_0);
        HSSFCell cellTime0_1 = rowTime.createCell(2);
        cellTime0_1.setCellValue("计划");
        centerCenterNoBorderCells.add(cellTime0_1);
        HSSFRow rowTime1 = sheet.createRow(9);
        HSSFCell cellTime1_1 = rowTime1.createCell(2);
        cellTime1_1.setCellValue("实际");
        centerCenterNoBorderCells.add(cellTime1_1);
        // 备注
        HSSFCell cellRemark = rowTime1.createCell(27);
        leftCenterCells.add(cellRemark);
        cellRemark.setCellValue("备注：\r\n" +
                "1. 阶段问题关闭率=本次已关闭问题数/待整改问题数、 总问题关闭率=总问题关闭数/总问题数；\r\n" +
                "2. 验证结果：P表示计划关闭、PY表示有计划且已关闭、PN表示有计划未关闭、Y表示直接关闭、“空白”表示本阶段未提出关闭要求；\r\n" +
                "3. 问题来源：客户、项目组、拆检组、产品检；\n" +
                "4. 每项整改问题钳工必须自检后品质才专检，并将结果记录在表单内，自检/专检确认均需签名并标注日期；\r\n" +
                "5. 问题关闭状态及原因由技术部方案组完成；\r\n" +
                "6. 必须填写实际试模时间，才能进行有效统计。");
        // 提出问题数
        HSSFRow rowProblemNum = sheet.createRow(10);
        HSSFCell cellProblemNum0_0 = rowProblemNum.createCell(0);
        cellProblemNum0_0.setCellValue("提出问题数");
        centerCenterNoBorderCells.add(cellProblemNum0_0);
        HSSFCell cellProblemNum0_1 = rowProblemNum.createCell(2);
        cellProblemNum0_1.setCellValue("新增问题数");
        centerCenterNoBorderCells.add(cellProblemNum0_1);
        HSSFRow rowProblemNum1 = sheet.createRow(11);
        HSSFCell cellProblemNum1_1 = rowProblemNum1.createCell(2);
        cellProblemNum1_1.setCellValue("问题总数");
        centerCenterNoBorderCells.add(cellProblemNum1_1);
        // 关闭问题数
        HSSFRow rowProblemClosed = sheet.createRow(12);
        HSSFCell cellProblemClosed0_0 = rowProblemClosed.createCell(0);
        cellProblemClosed0_0.setCellValue("关闭问题数");
        centerCenterNoBorderCells.add(cellProblemClosed0_0);
        HSSFCell cellProblemClosed0_1 = rowProblemClosed.createCell(2);
        cellProblemClosed0_1.setCellValue("计划本次解决数");
        centerCenterNoBorderCells.add(cellProblemClosed0_1);
        HSSFRow rowProblemClosed1 = sheet.createRow(13);
        HSSFCell cellProblemClosed1_1 = rowProblemClosed1.createCell(2);
        cellProblemClosed1_1.setCellValue("本次已关闭问题数");
        centerCenterNoBorderCells.add(cellProblemClosed1_1);
        HSSFRow rowProblemClosed2 = sheet.createRow(14);
        HSSFCell cellProblemClosed2_1 = rowProblemClosed2.createCell(2);
        cellProblemClosed2_1.setCellValue("★待整改问题数");
        centerCenterYellowBackCells.add(cellProblemClosed2_1);
        // 问题关闭率
        HSSFRow rowClosedPercent = sheet.createRow(15);
        HSSFCell cellClosedPercent0_0 = rowClosedPercent.createCell(0);
        cellClosedPercent0_0.setCellValue("问题关闭率");
        centerCenterNoBorderCells.add(cellClosedPercent0_0);
        HSSFCell cellClosedPercent0_1 = rowClosedPercent.createCell(2);
        cellClosedPercent0_1.setCellValue("阶段");
        centerCenterNoBorderCells.add(cellClosedPercent0_1);
        HSSFRow rowClosedPercent1 = sheet.createRow(16);
        HSSFCell cellClosedPercent1_1 = rowClosedPercent1.createCell(2);
        cellClosedPercent1_1.setCellValue("总数");
        centerCenterNoBorderCells.add(cellClosedPercent1_1);
        // 填充内容
        for (int i = 0; i < tryOutColsedQuestionStageData.size(); i++) {
            JSONObject item = (JSONObject) tryOutColsedQuestionStageData.get(i);
            // 试模原因
            HSSFCell cellReason0_T = rowReason.createCell(4 + i);
            cellReason0_T.setCellValue(item.get("reason").toString());
            centerCenterCells.add(cellReason0_T);
            // 试模时间 计划
            HSSFCell cellTime0_T = rowTime.createCell(4 + i);
            cellTime0_T.setCellValue(item.get("plannedTime").toString());
            centerCenterCells.add(cellTime0_T);
            // 试模时间 实际
            HSSFCell cellTime1_T = rowTime1.createCell(4 + i);
            cellTime1_T.setCellValue(item.get("realTime").toString());
            centerCenterCells.add(cellTime1_T);
            // 提出问题数 新增问题数
            HSSFCell cellProblemNum0_T = rowProblemNum.createCell(4 + i);
            cellProblemNum0_T.setCellValue(item.get("raisedCount").toString());
            centerCenterCells.add(cellProblemNum0_T);
            // 提出问题数 问题总数
            HSSFCell cellProblemNum1_T = rowProblemNum1.createCell(4 + i);
            cellProblemNum1_T.setCellValue(item.get("totalCount").toString());
            centerCenterCells.add(cellProblemNum1_T);
            // 关闭问题数 计划本次解决数
            HSSFCell cellProblemClosed0_T = rowProblemClosed.createCell(4 + i);
            cellProblemClosed0_T.setCellValue(item.get("plannedDoneCount").toString());
            centerCenterCells.add(cellProblemClosed0_T);
            // 关闭问题数 本次已关闭问题数
            HSSFCell cellProblemClosed1_T = rowProblemClosed1.createCell(4 + i);
            cellProblemClosed1_T.setCellValue(item.get("closedCount").toString());
            centerCenterCells.add(cellProblemClosed1_T);
            // 关闭问题数 ★待整改问题数
            HSSFCell cellProblemClosed2_T = rowProblemClosed2.createCell(4 + i);
            cellProblemClosed2_T.setCellValue(item.get("needToChangeCount").toString());
            centerCenterCells.add(cellProblemClosed2_T);
            // 问题关闭率 阶段
            HSSFCell cellClosedPercent0_T = rowClosedPercent.createCell(4 + i);
            cellClosedPercent0_T.setCellValue(item.get("stageCloseRate").toString());
            centerCenterCells.add(cellClosedPercent0_T);
            // 问题关闭率 总数
            HSSFCell cellClosedPercent1_T = rowClosedPercent1.createCell(4 + i);
            cellClosedPercent1_T.setCellValue(item.get("totalCloseRate").toString());
            centerCenterCells.add(cellClosedPercent1_T);
        }
        // T21/22
        for (int i = 7; i < 17; i++) {
            for (int j = 25; j < 27; j++) {
                HSSFRow row = sheet.getRow(i);
                centerCenterCells.add(row.createCell(j));
            }
        }
        HSSFRow row17 = sheet.createRow(17);
        HSSFCell cell17_0 = row17.createCell(0);
        cell17_0.setCellValue("序号");
        centerCenterNoBorderCells.add(cell17_0);
        HSSFCell cell17_1 = row17.createCell(1);
        cell17_1.setCellValue("问题提出阶段");
        centerCenterNoBorderCells.add(cell17_1);
        HSSFCell cell17_2 = row17.createCell(2);
        cell17_2.setCellValue("略图");
        centerCenterNoBorderCells.add(cell17_2);
        HSSFCell cell17_3 = row17.createCell(5);
        cell17_3.setCellValue("问题点内容");
        centerCenterNoBorderCells.add(cell17_3);
        HSSFCell cell17_7 = row17.createCell(10);
        cell17_7.setCellValue("原因分析");
        centerCenterNoBorderCells.add(cell17_7);
        HSSFCell cell17_9 = row17.createCell(15);
        cell17_9.setCellValue("问题来源");
        centerCenterNoBorderCells.add(cell17_9);
        HSSFCell cell17_10 = row17.createCell(16);
        cell17_10.setCellValue("责任部门");
        centerCenterNoBorderCells.add(cell17_10);
        HSSFCell cell17_11 = row17.createCell(17);
        cell17_11.setCellValue("责任人");
        centerCenterNoBorderCells.add(cell17_11);
        HSSFCell cell17_12 = row17.createCell(18);
        cell17_12.setCellValue("整改方案");
        centerCenterNoBorderCells.add(cell17_12);
        HSSFCell cell17_13 = row17.createCell(21);
        cell17_13.setCellValue("计划完成时间");
        centerCenterNoBorderCells.add(cell17_13);
        HSSFCell cell17_14 = row17.createCell(23);
        cell17_14.setCellValue("责任人自检");
        centerCenterNoBorderCells.add(cell17_14);
        HSSFCell cell17_15 = row17.createCell(25);
        cell17_15.setCellValue("专家组");
        centerCenterNoBorderCells.add(cell17_15);
        HSSFCell cell17_16 = row17.createCell(26);
        cell17_16.setCellValue("履历");
        centerCenterNoBorderCells.add(cell17_16);
        HSSFCell cell17_17 = row17.createCell(27);
        cell17_17.setCellValue("实验结果");
        centerCenterCells.add(cell17_17);

        HSSFRow row18 = sheet.createRow(18);
        HSSFCell cell18_3 = row18.createCell(5);
        cell18_3.setCellValue("问题点");
        centerCenterCells.add(cell18_3);
        HSSFCell cell18_4 = row18.createCell(7);
        cell18_4.setCellValue("问题归类");
        centerCenterCells.add(cell18_4);
        HSSFCell cell18_18 = row18.createCell(8);
        cell18_18.setCellValue("问题总数");
        centerCenterCells.add(cell18_18);
        HSSFCell cell18_6 = row18.createCell(9);
        cell18_6.setCellValue("待整改问题数");
        centerCenterCells.add(cell18_6);
        HSSFCell cell18_7 = row18.createCell(10);
        cell18_7.setCellValue("原因");
        centerCenterCells.add(cell18_7);
        HSSFCell cell18_8 = row18.createCell(14);
        cell18_8.setCellValue("原因归类");
        centerCenterCells.add(cell18_8);
        // T1-TW
        for (int i = 0; i < 20; i++) {
            HSSFCell cell18_T = row18.createCell(27 + i);
            cell18_T.setCellValue("T" + (i + 1));
            centerCenterCells.add(cell18_T);
        }
        HSSFCell cell18_37 = row18.createCell(47);
        cell18_37.setCellValue("TW");
        centerCenterCells.add(cell18_37);

        List<RecordProblemVo> stageData = tryOutRecordListItem.getStageData();
        int stageDataSize = stageData.size();
        // 合并问题提出阶段列表的单元格
        for (int i = 0; i < stageDataSize; i++) {
            CellRangeAddress cellAddresses45 = CellRangeAddress.valueOf("A" + (20 + i * 3) + ":A" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses45);
            rangeCells.add(cellAddresses45);
            CellRangeAddress cellAddresses46 = CellRangeAddress.valueOf("B" + (20 + i * 3) + ":B" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses46);
            rangeCells.add(cellAddresses46);
            CellRangeAddress cellAddresses47 = CellRangeAddress.valueOf("C" + (20 + i * 3) + ":E" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses47);
            rangeCells.add(cellAddresses47);
            CellRangeAddress cellAddresses48 = CellRangeAddress.valueOf("F" + (20 + i * 3) + ":G" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses48);
            rangeCells.add(cellAddresses48);
            CellRangeAddress cellAddresses49 = CellRangeAddress.valueOf("H" + (20 + i * 3) + ":H" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses49);
            rangeCells.add(cellAddresses49);
            CellRangeAddress cellAddresses50 = CellRangeAddress.valueOf("I" + (20 + i * 3) + ":I" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses50);
            rangeCells.add(cellAddresses50);
            CellRangeAddress cellAddresses51 = CellRangeAddress.valueOf("J" + (20 + i * 3) + ":J" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses51);
            rangeCells.add(cellAddresses51);
            CellRangeAddress cellAddresses52 = CellRangeAddress.valueOf("K" + (20 + i * 3) + ":N" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses52);
            rangeCells.add(cellAddresses52);
            CellRangeAddress cellAddresses53 = CellRangeAddress.valueOf("O" + (20 + i * 3) + ":O" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses53);
            rangeCells.add(cellAddresses53);
            CellRangeAddress cellAddresses54 = CellRangeAddress.valueOf("P" + (20 + i * 3) + ":P" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses54);
            rangeCells.add(cellAddresses54);
            CellRangeAddress cellAddresses55 = CellRangeAddress.valueOf("Z" + (20 + i * 3) + ":Z" + (20 + i * 3 + 2));
            sheet.addMergedRegion(cellAddresses55);
            rangeCells.add(cellAddresses55);
            // 填充内容
            RecordProblemVo recordProblemVo = stageData.get(i);
            HSSFRow rowT1 = sheet.createRow(19 + i * 3);
            HSSFCell cellT1_0 = rowT1.createCell(0);
            cellT1_0.setCellValue(i + 1);
            centerCenterCells.add(cellT1_0);
            HSSFCell cellT1_1 = rowT1.createCell(1);
            cellT1_1.setCellValue(recordProblemVo.getStageNo());
            centerCenterCells.add(cellT1_1);
            HSSFCell cellT1_2 = rowT1.createCell(2);
            String imageUrl = recordProblemVo.getImage();
            if (StringUtils.isNotEmpty(imageUrl)) {
                int rowIndex = cellT1_2.getRowIndex();
                int columnIndex = cellT1_2.getColumnIndex();
                try {
                    setImageToExcel(workbook, sheet, keyWord.getFileUrl() + File.separator + imageUrl.substring(imageUrl.indexOf("file/")), (short) columnIndex, rowIndex, (short) (columnIndex + 2), rowIndex + 2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
//            cellT1_2.setCellValue(recordProblemVo.getImage());
            centerCenterCells.add(cellT1_2);
            HSSFCell cellT1_3 = rowT1.createCell(5);
            cellT1_3.setCellValue(recordProblemVo.getQuestionPoint());
            centerCenterCells.add(cellT1_3);
            HSSFCell cellT1_4 = rowT1.createCell(7);
            DictTable dictTableQuestionTypeName = dictTableMapper.selectById(recordProblemVo.getQuestionTypeName());
            String questionTypeName = "";
            if (null != dictTableQuestionTypeName) {
                questionTypeName = dictTableQuestionTypeName.getDicName();
            }
            cellT1_4.setCellValue(questionTypeName);
            centerCenterCells.add(cellT1_4);
            HSSFCell cellT1_5 = rowT1.createCell(8);
            cellT1_5.setCellValue(recordProblemVo.getTotalQuestionCount());
            centerCenterCells.add(cellT1_5);
            HSSFCell cellT1_6 = rowT1.createCell(9);
            cellT1_6.setCellValue(recordProblemVo.getNeedToChangeCount());
            centerCenterCells.add(cellT1_6);
            HSSFCell cellT1_7 = rowT1.createCell(10);
            cellT1_7.setCellValue(recordProblemVo.getReason());
            centerCenterCells.add(cellT1_7);
            HSSFCell cellT1_8 = rowT1.createCell(14);
            DictTable dictTableReasonTypeName = dictTableMapper.selectById(recordProblemVo.getReasonTypeName());
            String reasonTypeName = "";
            if (null != dictTableReasonTypeName) {
                reasonTypeName = dictTableReasonTypeName.getDicName();
            }
            cellT1_8.setCellValue(reasonTypeName);
            centerCenterCells.add(cellT1_8);
            HSSFCell cellT1_9 = rowT1.createCell(15);
            DictTable dictTableReasonSource = dictTableMapper.selectById(recordProblemVo.getReasonSourceId());
            String reasonSource = "";
            if (null != dictTableReasonSource) {
                reasonSource = dictTableReasonSource.getDicName();
            }
            cellT1_9.setCellValue(reasonSource);
            centerCenterCells.add(cellT1_9);
            HSSFCell cellT1_15 = rowT1.createCell(25);
            DictTable dictTableExpertGroup = dictTableMapper.selectById(recordProblemVo.getExpertGroup());
            String expertGroup = "";
            if (null != dictTableExpertGroup) {
                expertGroup = dictTableExpertGroup.getDicName();
            }
            cellT1_15.setCellValue(expertGroup);
            centerCenterCells.add(cellT1_15);

            // 责任部门、责任人等 合并单元格
            List<RecordSourceVo> responsiblePersonData = recordProblemVo.getResponsiblePersonData();
            List<RecordResumeVo> tryOutResultData = recordProblemVo.getTryOutResultData();
            for (int j = 0; j < 3; j++) {
                HSSFRow rowIs = null;
                rowIs = sheet.getRow(19 + i * 3 + j);
                if (null == rowIs) {
                    rowIs = sheet.createRow(19 + i * 3 + j);
                }
                centerCenterCells.add(rowIs.createCell(16));
                centerCenterCells.add(rowIs.createCell(17));
                CellRangeAddress cellAddresses19_0 = CellRangeAddress.valueOf("S" + (20 + i * 3 + j) + ":U" + (20 + i * 3 + j));
                sheet.addMergedRegion(cellAddresses19_0);
                rangeCells.add(cellAddresses19_0);
                CellRangeAddress cellAddresses19_1 = CellRangeAddress.valueOf("V" + (20 + i * 3 + j) + ":W" + (20 + i * 3 + j));
                sheet.addMergedRegion(cellAddresses19_1);
                rangeCells.add(cellAddresses19_1);
                CellRangeAddress cellAddresses19_2 = CellRangeAddress.valueOf("X" + (20 + i * 3 + j) + ":Y" + (20 + i * 3 + j));
                sheet.addMergedRegion(cellAddresses19_2);
                rangeCells.add(cellAddresses19_2);
            }
            // 责任部门、责任人等 添加内容
            if (responsiblePersonData.size() == 0) {
                for (int is = 0; is < 1; is++) {
                    HSSFRow rowIs = sheet.getRow(19 + i * 3 + is);
                    rowIs.setHeight((short) (40 * 20));
                    HSSFCell cell10 = rowIs.getCell(16);
                    cell10.setCellValue("");
                    centerCenterCells.add(cell10);
                    HSSFCell cell11 = rowIs.getCell(17);
                    cell11.setCellValue("");
                    centerCenterCells.add(cell11);
                    HSSFCell cell12 = rowIs.getCell(18);
                    cell12.setCellValue("");
                    centerCenterCells.add(cell12);
                    HSSFCell cell13 = rowIs.getCell(21);
                    cell13.setCellValue("");
                    centerCenterCells.add(cell13);
                    HSSFCell cell14 = rowIs.getCell(23);
                    cell14.setCellValue("");
                    centerCenterCells.add(cell14);
                    HSSFRow rowResult0 = sheet.getRow(19 + i * 3 + is);
                    for (int j = 28; j <= 49; j++) {
                        centerCenterCells.add(rowResult0.createCell(j));
                    }
                    HSSFRow rowResult1 = sheet.getRow(19 + i * 3 + is + 1);
                    for (int j = 28; j <= 49; j++) {
                        centerCenterCells.add(rowResult1.createCell(j));
                    }
                    HSSFRow rowResult2 = sheet.getRow(19 + i * 3 + is + 2);
                    for (int j = 28; j <= 49; j++) {
                        centerCenterCells.add(rowResult2.createCell(j));
                    }
                    HSSFCell cellState = rowResult0.getCell(26);
                    cellState.setCellValue("状态");
                    centerCenterCells.add(cellState);
                    HSSFCell cellPlan = rowResult1.getCell(26);
                    cellPlan.setCellValue("计划");
                    centerCenterCells.add(cellPlan);
                    HSSFCell cellReal = rowResult2.getCell(26);
                    cellReal.setCellValue("实际");
                    centerCenterCells.add(cellReal);
                }
            } else {
                for (int is = 0; is < responsiblePersonData.size(); is++) {
                    RecordSourceVo recordSourceVo = responsiblePersonData.get(is);
                    HSSFRow rowIs = sheet.getRow(19 + i * 3 + is);
                    rowIs.setHeight((short) (40 * 20));
                    HSSFCell cell10 = rowIs.createCell(16);
                    DictTable dictTableDepartMentName = dictTableMapper.selectById(recordSourceVo.getDepartMentName());
                    String departMentName = "";
                    if (null != dictTableDepartMentName) {
                        departMentName = dictTableDepartMentName.getDicName();
                    }
                    cell10.setCellValue(departMentName);
                    centerCenterCells.add(cell10);
                    HSSFCell cell11 = rowIs.createCell(17);
                    cell11.setCellValue(oaUserService.getOaUserName(recordSourceVo.getResponsiblePerson()));
                    centerCenterCells.add(cell11);
                    HSSFCell cell12 = rowIs.createCell(18);
                    cell12.setCellValue(recordSourceVo.getRemediationAction());
                    centerCenterCells.add(cell12);
                    HSSFCell cell13 = rowIs.createCell(21);
                    cell13.setCellValue(recordSourceVo.getPlannedCompletionTime());
                    centerCenterCells.add(cell13);
                    HSSFCell cell14 = rowIs.createCell(23);
                    cell14.setCellValue(oaUserService.getOaUserName(recordSourceVo.getSelfCheck()));
                    centerCenterCells.add(cell14);
                    if (tryOutResultData.size() > 0 && 0 == is) {
                        RecordResumeVo recordResumeVo = tryOutResultData.get(0);
                        HSSFRow rowResult0 = sheet.getRow(19 + i * 3 + is);
                        for (int j = 27; j <= 47; j++) {
                            centerCenterCells.add(rowResult0.createCell(j));
                        }
                        HSSFRow rowResult1 = sheet.getRow(19 + i * 3 + is + 1);
                        for (int j = 27; j <= 47; j++) {
                            centerCenterCells.add(rowResult1.createCell(j));
                        }
                        HSSFRow rowResult2 = sheet.getRow(19 + i * 3 + is + 2);
                        for (int j = 27; j <= 47; j++) {
                            centerCenterCells.add(rowResult2.createCell(j));
                        }
//                        String tx = recordResumeVo.getStageName().substring(1);
//                        Integer stageN0 = Integer.valueOf(tx);
                        HSSFCell cellState = rowResult0.createCell(26);
                        cellState.setCellValue("状态");
                        centerCenterCells.add(cellState);
                        HSSFCell cellPlan = rowResult1.createCell(26);
                        cellPlan.setCellValue("计划");
                        centerCenterCells.add(cellPlan);
                        HSSFCell cellReal = rowResult2.createCell(26);
                        cellReal.setCellValue("实际");
                        centerCenterCells.add(cellReal);
                        // 实验结果内容
//                        if (0 != stageN0) {
                        for (int i1 = 0; i1 < tryOutResultData.size(); i1++) {
                            RecordResumeVo recordResumeVoT = tryOutResultData.get(i1);
                            String stateValue = "";
                            String plan = "";
                            String real = "";
                            if (null != recordResumeVoT) {
                                stateValue = recordResumeVoT.getStateValue();
                                plan = recordResumeVoT.getPlanValue();
                                real = recordResumeVoT.getRealValue();
                            }
                            HSSFCell cell0 = rowResult0.createCell(27 + i1);
                            cell0.setCellValue(stateValue);
                            switch (stateValue) {
                                case "P": {
                                    centerCenterBlankYellowBackCells.add(cell0);
                                    break;
                                }
                                case "PY":
                                case "Y": {
                                    centerCenterGreenBackCells.add(cell0);
                                    break;
                                }
                                case "PN": {
                                    centerCenterRedBackCells.add(cell0);
                                    break;
                                }
                                default:
                                    centerCenterCells.add(cell0);
                            }
                            centerCenterCells.add(cell0);
                            HSSFCell cell1 = rowResult1.createCell(27 + i1);
                            cell1.setCellValue(plan);
                            centerCenterCells.add(cell1);
                            HSSFCell cell2 = rowResult2.createCell(27 + i1);
                            cell2.setCellValue(real);
                            centerCenterCells.add(cell2);
                        }

//                        }
                    }
                }
            }

        }
        /**
         * 最后一行 start
         */
        CellRangeAddress cellAddresses = CellRangeAddress.valueOf("A" + (20 + stageDataSize * 3) + ":B" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses);
        rangeCells.add(cellAddresses);
        CellRangeAddress cellAddresses1 = CellRangeAddress.valueOf("C" + (20 + stageDataSize * 3) + ":J" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses1);
        rangeCells.add(cellAddresses1);
        CellRangeAddress cellAddresses2 = CellRangeAddress.valueOf("K" + (20 + stageDataSize * 3) + ":L" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses2);
        rangeCells.add(cellAddresses2);
        CellRangeAddress cellAddresses3 = CellRangeAddress.valueOf("M" + (20 + stageDataSize * 3) + ":S" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses3);
        rangeCells.add(cellAddresses3);
        CellRangeAddress cellAddresses4 = CellRangeAddress.valueOf("T" + (20 + stageDataSize * 3) + ":U" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses4);
        rangeCells.add(cellAddresses4);
        CellRangeAddress cellAddresses5 = CellRangeAddress.valueOf("V" + (20 + stageDataSize * 3) + ":AV" + (20 + stageDataSize * 3));
        sheet.addMergedRegion(cellAddresses5);
        rangeCells.add(cellAddresses5);
        HSSFRow rowEnd = sheet.createRow(19 + stageDataSize * 3);
        HSSFCell cell0 = rowEnd.createCell(0);
        cell0.setCellValue("拟制人：");
        rightCenterCells.add(cell0);
        HSSFCell cell6 = rowEnd.createCell(2);
        String preparer = "";
        UserApi userApi = userApiMapper.selectById(recordMainTable.getPreparer());
        if (ObjectUtil.isNotNull(userApi)) {
            preparer = userApi.getName();
        }
        cell6.setCellValue(preparer);
        leftCenterCells.add(cell6);
        HSSFCell cell11 = rowEnd.createCell(10);
        cell11.setCellValue("审核：");
        rightCenterCells.add(cell11);
        HSSFCell cell15 = rowEnd.createCell(12);
        cell15.setCellValue(recordMainTable.getAuditor());
        leftCenterCells.add(cell15);
        HSSFCell cell22 = rowEnd.createCell(19);
        cell22.setCellValue("会签：");
        rightCenterCells.add(cell22);
        HSSFCell cell29 = rowEnd.createCell(21);
        cell29.setCellValue(recordMainTable.getCountersign());
        leftCenterCells.add(cell29);
        /**
         * 最后一行 end
         */
        HSSFCellStyle styleRightCenter = workbook.createCellStyle();
        styleRightCenter.setBorderTop(BorderStyle.THIN);
        styleRightCenter.setBorderBottom(BorderStyle.THIN);
        styleRightCenter.setBorderLeft(BorderStyle.THIN);
        styleRightCenter.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleRightCenter.setAlignment(HorizontalAlignment.RIGHT);
        // 垂直布局：居中
        styleRightCenter.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleRightCenter.setWrapText(true);
        // 加粗字体
        styleRightCenter.setFont(boldFont);
        for (HSSFCell rightCenterCell : rightCenterCells) {
            rightCenterCell.setCellStyle(styleRightCenter);
        }
        HSSFCellStyle styleLeftCenter = workbook.createCellStyle();
        styleLeftCenter.setBorderTop(BorderStyle.THIN);
        styleLeftCenter.setBorderBottom(BorderStyle.THIN);
        styleLeftCenter.setBorderLeft(BorderStyle.THIN);
        styleLeftCenter.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleLeftCenter.setAlignment(HorizontalAlignment.LEFT);
        // 垂直布局：居中
        styleLeftCenter.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleLeftCenter.setWrapText(true);
        for (HSSFCell leftCenterCell : leftCenterCells) {
            leftCenterCell.setCellStyle(styleLeftCenter);
        }

        HSSFCellStyle styleCenterCenterNoBorder = workbook.createCellStyle();
        // 水平布局：居中
        styleCenterCenterNoBorder.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenterNoBorder.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenterNoBorder.setWrapText(true);
        for (HSSFCell centerCenterNoBorderCell : centerCenterNoBorderCells) {
            centerCenterNoBorderCell.setCellStyle(styleCenterCenterNoBorder);
        }
        HSSFCellStyle styleCenterCenter = workbook.createCellStyle();
        styleCenterCenter.setBorderTop(BorderStyle.THIN);
        styleCenterCenter.setBorderBottom(BorderStyle.THIN);
        styleCenterCenter.setBorderLeft(BorderStyle.THIN);
        styleCenterCenter.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleCenterCenter.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenter.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenter.setWrapText(true);
        for (HSSFCell centerCenterCell : centerCenterCells) {
            centerCenterCell.setCellStyle(styleCenterCenter);
        }
        // 黄色背景
        HSSFCellStyle styleCenterCenterYellowBack = workbook.createCellStyle();
        styleCenterCenterYellowBack.setBorderTop(BorderStyle.THIN);
        styleCenterCenterYellowBack.setBorderBottom(BorderStyle.THIN);
        styleCenterCenterYellowBack.setBorderLeft(BorderStyle.THIN);
        styleCenterCenterYellowBack.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleCenterCenterYellowBack.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenterYellowBack.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenterYellowBack.setWrapText(true);
        styleCenterCenterYellowBack.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); // 设置背景色为黄色
        styleCenterCenterYellowBack.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 设置背景色为黄色
        for (HSSFCell centerCenterCell : centerCenterYellowBackCells) {
            centerCenterCell.setCellStyle(styleCenterCenterYellowBack);
        }
        // 绿色背景
        HSSFCellStyle styleCenterCenterGreenBack = workbook.createCellStyle();
        styleCenterCenterGreenBack.setBorderTop(BorderStyle.THIN);
        styleCenterCenterGreenBack.setBorderBottom(BorderStyle.THIN);
        styleCenterCenterGreenBack.setBorderLeft(BorderStyle.THIN);
        styleCenterCenterGreenBack.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleCenterCenterGreenBack.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenterGreenBack.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenterGreenBack.setWrapText(true);
        styleCenterCenterGreenBack.setFillForegroundColor(IndexedColors.GREEN.getIndex()); // 设置背景色为绿色
        styleCenterCenterGreenBack.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 设置背景色为绿色
        for (HSSFCell centerCenterCell : centerCenterGreenBackCells) {
            centerCenterCell.setCellStyle(styleCenterCenterGreenBack);
        }
        // 红色背景
        HSSFCellStyle styleCenterCenterRedBack = workbook.createCellStyle();
        styleCenterCenterRedBack.setBorderTop(BorderStyle.THIN);
        styleCenterCenterRedBack.setBorderBottom(BorderStyle.THIN);
        styleCenterCenterRedBack.setBorderLeft(BorderStyle.THIN);
        styleCenterCenterRedBack.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleCenterCenterRedBack.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenterRedBack.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenterRedBack.setWrapText(true);
        styleCenterCenterRedBack.setFillForegroundColor(IndexedColors.RED.getIndex()); // 设置背景色为红色
        styleCenterCenterRedBack.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 设置背景色为红色
        for (HSSFCell centerCenterCell : centerCenterRedBackCells) {
            centerCenterCell.setCellStyle(styleCenterCenterRedBack);
        }
        // 屎黄背景
        HSSFCellStyle styleCenterCenterBlankYellowBack = workbook.createCellStyle();
        styleCenterCenterBlankYellowBack.setBorderTop(BorderStyle.THIN);
        styleCenterCenterBlankYellowBack.setBorderBottom(BorderStyle.THIN);
        styleCenterCenterBlankYellowBack.setBorderLeft(BorderStyle.THIN);
        styleCenterCenterBlankYellowBack.setBorderRight(BorderStyle.THIN);
        // 水平布局：居中
        styleCenterCenterBlankYellowBack.setAlignment(HorizontalAlignment.CENTER);
        // 垂直布局：居中
        styleCenterCenterBlankYellowBack.setVerticalAlignment(VerticalAlignment.CENTER);
        // 自动换行
        styleCenterCenterBlankYellowBack.setWrapText(true);
        styleCenterCenterBlankYellowBack.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); // 设置背景色为屎黄
        styleCenterCenterBlankYellowBack.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 设置背景色为屎黄
        for (HSSFCell centerCenterCell : centerCenterBlankYellowBackCells) {
            centerCenterCell.setCellStyle(styleCenterCenterBlankYellowBack);
        }

        for (CellRangeAddress addresses : rangeCells) {
            RegionUtil.setBorderLeft(BorderStyle.THIN, addresses, sheet);
            RegionUtil.setBorderTop(BorderStyle.THIN, addresses, sheet);
            RegionUtil.setBorderRight(BorderStyle.THIN, addresses, sheet);
            RegionUtil.setBorderBottom(BorderStyle.THIN, addresses, sheet);
        }

        /**
         *试模问题关闭统计表 导出
         */
        exportTestProblemStatisticsRecord(workbook, moldId);

        /**
         * excel 操作结束
         */
        String fileUrl = "/file/excel/" + DateUtil.format(new Date(), "yyyyMMddHHmmss");
        FileUtil.mkdir(keyWord.getFileUrl() + fileUrl);
        //创建文件输出流
        OutputStream os = new FileOutputStream(keyWord.getFileUrl() + fileUrl + "/试模评审记录表.xlsx");
        //将文件放入流
        workbook.write(os);
        //刷新流
        os.flush();
        os.close();
        workbook.close();

        return JSON.toJSONString(R.data(fileUrl + "/试模评审记录表.xlsx"));
    }


    /**
     * 试模问题关闭统计表 导出
     *
     * @param workbook
     * @param moldId
     */
    private void exportTestProblemStatisticsRecord(HSSFWorkbook workbook, String moldId) {
        HSSFSheet sheet = workbook.createSheet("试模问题关闭统计表");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("moldId", moldId);
        String tryOutColsedQuestion = closeQuestionService.tryOutColsedQuestion(jsonObject);
        JSONObject parseObject = (JSONObject) JSON.parseObject(tryOutColsedQuestion).get("data");
        /**
         * 项目信息
         */
        Map<String, int[]> projectInfoMap = new HashMap<>();
        projectInfoMap.put("项目名称", new int[]{0, 0});
        projectInfoMap.put(parseObject.getString("projectName"), new int[]{0, 1});
        projectInfoMap.put("产品名称", new int[]{0, 2});
        projectInfoMap.put(parseObject.getString("moldName"), new int[]{0, 3});
        projectInfoMap.put("模具工号", new int[]{0, 4});
        projectInfoMap.put(parseObject.getString("moldId"), new int[]{0, 5});
        projectInfoMap.put("产品材质", new int[]{0, 6});
        projectInfoMap.put(parseObject.getString("moldMaterial"), new int[]{0, 7});
        projectInfoMap.put("产品重量", new int[]{0, 8});
        projectInfoMap.put(parseObject.getString("moldWeight"), new int[]{0, 9});
        projectInfoMap.put("主机厂", new int[]{0, 10});
        projectInfoMap.put(parseObject.getString("mainEnginePlantId"), new int[]{0, 11});

        String partsStorageBin = parseObject.getString("partsStorageBin");
        if (StringUtils.isNotBlank(partsStorageBin)) {
            DictTable dictTable = dictTableMapper.selectById(partsStorageBin);
            partsStorageBin = Objects.nonNull(dictTable) ? dictTable.getDicName() : "";
        }

        projectInfoMap.put("项目负责人", new int[]{1, 0});
        projectInfoMap.put(parseObject.getString("projectManager"), new int[]{1, 1});
        projectInfoMap.put("项目设计人", new int[]{1, 2});
        projectInfoMap.put(parseObject.getString("moldDesigner"), new int[]{1, 3});
        projectInfoMap.put("钳工责任人", new int[]{1, 4});
        projectInfoMap.put(parseObject.getString("tongmanName"), new int[]{1, 5});
        projectInfoMap.put("产品表面要求", new int[]{1, 6});
        projectInfoMap.put(parseObject.getString("surfaceRequire"), new int[]{1, 7});
        projectInfoMap.put("零件厂", new int[]{1, 8});
        projectInfoMap.put(partsStorageBin, new int[]{1, 9});
        projectInfoMap.put("T0", new int[]{1, 10});
        projectInfoMap.put(parseObject.getString("tryOutTime"), new int[]{1, 11});

        projectInfoMap.forEach((k, v) -> {
            PoiUtils.getRow(sheet, v[0]).createCell(v[1]).setCellValue(k);
        });

        int row = 2, col = 0;
        PoiUtils.mergedRegion(sheet, row, row, col, col + 1, "试模阶段");
        int num = 20;
        for (int i = 0; i <= num; i++) {
            PoiUtils.getRow(sheet, row).createCell(i + 2).setCellValue("T" + i);
        }
        row++;
        int rowIndex = row;
        PoiUtils.mergedRegion(sheet, row, row, col, col + 1, "试模原因");
        JSONArray stageDataArray = parseObject.getJSONArray("stageData");
        if (Objects.nonNull(stageDataArray) && !stageDataArray.isEmpty()) {
            String[] keys = {"reason", "plannedTime", "realTime", "raisedCount", "totalCount", "plannedDoneCount",
                    "closedCount", "needToChangeCount", "stageCloseRate", "totalCloseRate"};
            for (int j = 0; j < keys.length; j++) {
                for (int i = 0; i < stageDataArray.size(); i++) {
                    JSONObject stageData = stageDataArray.getJSONObject(i);
                    PoiUtils.getRow(sheet, rowIndex).createCell(i + 2).setCellValue(stageData.getString(keys[j]));
                }
                rowIndex++;
            }
        }
        row++;
        PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "试模时间");
        PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("计划");
        PoiUtils.getRow(sheet, row + 1).createCell(col + 1).setCellValue("实际");
        row += 2;
        PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "提出问题数");
        PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("新增问题数");
        PoiUtils.getRow(sheet, row + 1).createCell(col + 1).setCellValue("问题总数");
        row += 2;
        PoiUtils.mergedRegion(sheet, row, row + 2, col, col, "关闭问题数");
        PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("计划本次解决数");
        PoiUtils.getRow(sheet, row + 1).createCell(col + 1).setCellValue("本次已关闭问题数");
        PoiUtils.getRow(sheet, row + 2).createCell(col + 1).setCellValue("待整改问题数");
        row += 3;
        PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "问题关闭率");
        PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("阶段");
        PoiUtils.getRow(sheet, row + 1).createCell(col + 1).setCellValue("总数");

        // 设置整个表格的样式
        sheet.forEach(sheetRow -> {
            sheetRow.forEach(cell -> {
                cell.setCellStyle(createCellStyle(workbook));
            });
            // 设置行高自适应
            sheetRow.setHeight((short) -1);
            // 遍历每个单元格
            for (int colIndex = 0; colIndex < sheetRow.getLastCellNum(); colIndex++) {
                Cell cell = sheetRow.getCell(colIndex);
                if (cell != null) {
                    cell.setCellStyle(createCellStyle(workbook));
                    // 计算并设置列宽
                    String cellValue = cell.toString();
                    // 计算宽度，加1个字符的宽度
                    int width = (cellValue.getBytes().length + 1) * 256;
                    sheet.setColumnWidth(colIndex, Math.max(sheet.getColumnWidth(colIndex), width));
                }
            }
        });
    }

    private void setImageToExcel(Workbook workbook, Sheet sheet, String url, short cellS, int rowS, short cellE, int rowE) {
        try {

            ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
            BufferedImage bufferImg = ImageIO.read(new File(url));

            // 将图片写入流中
            ImageIO.write(bufferImg, "png", byteArrayOut);
            // 利用HSSFPatriarch将图片写入EXCEL
            Drawing patriarch = sheet.createDrawingPatriarch();
            /**
             * 该构造函数有8个参数
             * 前四个参数是控制图片在单元格的位置，分别是图片距离单元格left，top，right，bottom的像素距离
             * 后四个参数，前连个表示图片左上角所在的cellNum和 rowNum，后天个参数对应的表示图片右下角所在的cellNum和 rowNum，
             * excel中的cellNum和rowNum的index都是从0开始的
             *
             */
            //图片一导出到单元格
            HSSFClientAnchor anchor = new HSSFClientAnchor(500, 200, 0, 0,
                    cellS, rowS, cellE, rowE);
            // 插入图片
            patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));

        } catch (IOException e) {

        }
    }

    @Override
    public String addTryOutColsedQuestion(JSONObject jsonObject) {
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取试模阶段数据
        JSONArray stageData = jsonObject.getJSONArray("stageData");
        if (
                "1".equals(moldId)
                        &&
                        "[{\"realTime\":\"4\",\"reason\":\"1\",\"stageName\":\"T0\",\"totalCloseRate\":\"1\",\"raisedCount\":\"4\",\"stageCloseRate\":\"1\",\"plannedTime\":\"2023-06-06\",\"plannedDoneCount\":\"3\",\"totalCount\":\"5\",\"needToChangeCount\":\"4\",\"closedCount\":\"3\"}]".equals(JSON.toJSONString(stageData))
        ) {
            return "{\"msg\":\"保存成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    /**
     * 设置单元格样式
     */
    private HSSFCellStyle createCellStyle(HSSFWorkbook workbook) {
        HSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //加边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        cellStyle.setFillForegroundColor((short) 9);
        cellStyle.setWrapText(true);
        HSSFFont font = workbook.createFont();
        //设置字体名称
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 11);
        //设置字体颜色
        font.setColor(IndexedColors.BLACK1.index);
        cellStyle.setFont(font);

        return cellStyle;
    }


}
